import request from '@/utils/request'

/**
 * 任务相关 API 接口
 */
export const taskApi = {

    // 新增：通过业务ID查询运行时任务（审批记录）
    getRuntimeTasks(businessId, taskId) {
        return request({
            url: '/api/workflow/runtime-tasks',
            method: 'get',
            params: {businessId, taskId}
        })
    },

    // 处理任务
    processTasks(data) {
        return request({
            url: '/api/workflow/runtime-tasks/process',
            method: 'POST',
            data
        })
    },

    /**
     * 获取任务操作配置
     * @param {number|string} taskId 任务 ID
     * @returns {Promise} 返回任务操作配置数组，例如：
     * [{ value: "APPROVED", label: "同意" }, { value: "DISAPPROVED", label: "拒绝" }, ...]
     */
    getTaskOperations(taskId) {
        return request({
            url: '/api/workflow/task/operations',
            method: 'get',
            params: {taskId}
        })
    },

    /**
     * 获取任务的下一步可选节点
     * @param {number|string} taskId 任务ID
     * @returns {Promise} 返回下一步节点列表，例如：
     * [{ id: "1", name: "部门经理审批", code: "manager_approve" }, ...]
     */
    getNextNodes(taskId) {
        return request({
            url: '/api/workflow/task/next-nodes',
            method: 'get',
            params: {taskId}
        })
    },

    /**
     * 获取节点的处理人和部门信息
     * @param {number|string} nodeId 节点ID
     * @returns {Promise} 返回节点信息，包含处理人和部门列表，例如：
     * {
     *   approvers: [{ userId: "1", nickName: "张三" }, ...],
     *   departments: [{ deptId: "1", deptName: "技术部" }, ...],
     *   defaultApprovers: ["1", "2"],
     *   defaultDepartments: ["1", "3"]
     * }
     */
    getNodeInfo(nodeId) {
        return request({
            url: '/api/workflow/node/info',
            method: 'get',
            params: {nodeId}
        })
    },

    // 获取审批记录
    getAnAuditTrail: (instanceId) => {
        return request({
            url: '/api/workflow/getAnAuditTrail',
            method: 'get',
            params: {businessId: instanceId}
        })
    }
} 